package zipkin.server.config;


import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
import org.springframework.cloud.consul.discovery.HeartbeatProperties;
import org.springframework.cloud.consul.discovery.TtlScheduler;
import org.springframework.cloud.consul.serviceregistry.ConsulRegistration;
import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry;

import com.ecwid.consul.v1.ConsulClient;

public class CzConsulServiceRegistry extends ConsulServiceRegistry {

  public CzConsulServiceRegistry(ConsulClient client, ConsulDiscoveryProperties properties, TtlScheduler ttlScheduler,
                                 HeartbeatProperties heartbeatProperties) {
    super(client, properties, ttlScheduler, heartbeatProperties);
  }

  @Override
  public void register(ConsulRegistration reg) {
    String name = reg.getService().getName();
    String ip = reg.getService().getAddress();
    String port = reg.getService().getPort().toString();

    reg.getService().setId(name + "-" + ip + "-" + port);

    super.register(reg);
  }

}

